<%= form_for @user, html: {class: 'edit_user'} do |f| %>
    <div class="row mt mb">

      <div class="medium-6 columns">

        <h5><%= t(:account_settings) %></h5>

        <p><%= t(:only_fill_in_passwords_when_modifying) %></p>

        <% if can? :create, User %>
            <%= f.text_field :email, tabindex: tabindex %>
        <% end %>

        <%= f.text_field :name, tabindex: tabindex %>

        <%= f.password_field :password, tabindex: tabindex %>

        <%= f.password_field :password_confirmation, tabindex: tabindex %>

        <% if can? :create, User %>
            <%= f.check_box :agent, label: t(:user_is_an_agent), tabindex: tabindex %>
        <% end %>

        <%= f.check_box :active, label: t(:active), tabindex: tabindex %>

        <%= f.select :time_zone, @time_zones, {}, tabindex: tabindex %>

        <%= f.select :locale, @locales, {}, tabindex: tabindex %>

        <%= f.select :per_page, [10, 20, 30, 50, 75, 100], {}, tabindex: tabindex %>

      </div>

      <div class="medium-6 columns">

        <% if @user.agent? %>

          <h5><%= t(:notification_settings) %></h5>

          <label>
            <%= f.radio_button :schedule_enabled, false, label: false %>
            <%= t('activerecord.attributes.user.schedule_enabled_false') %>
          </label>

          <label>
            <%= f.radio_button :schedule_enabled, true, label: false %>
            <%= t('activerecord.attributes.user.schedule_enabled_true') %>
          </label>

          <div data-work-can-wait style="<%= @user.schedule_enabled? ?
              'display: block;' : 'display: none;' %>">
            <%= f.fields_for :schedule, build_schedule_for_user do |ff|  %>
              <div class="row">
                <div class="small-5 medium-4 large-3 columns">
                  <%
                    selected = '8:00'
                    unless ff.object.start.nil?
                      selected = "#{ff.object.start.hour}:00"
                    end
                  %>
                  <%= ff.select :start,
                      options_for_select((0..23).map { |n| "#{n}:00" }, selected),
                      label: false %>
                </div>
                <div class="small-2 medium-2 large-1 column">
                  <label class="inline text-center">
                    <%= t(:until) %>
                  </label>
                </div>
                <div class="small-5 medium-4 large-3 columns end">
                  <%
                    selected = '18:00'
                    unless ff.object.end.nil?
                      selected = "#{ff.object.end.hour}:00"
                    end
                  %>
                  <%= ff.select :end,
                      options_for_select((0..23).map { |n| "#{n}:00" }, selected),
                      label: false %>
                </div>
              </div>
              <label class="checkbox-helper">
                <%= ff.check_box :sunday, label: false %>
                <span><%= localize_day_name(0).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :monday, label: false %>
                <span><%= localize_day_name(1).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :tuesday, label: false %>
                <span><%= localize_day_name(2).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :wednesday, label: false %>
                <span><%= localize_day_name(3).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :thursday, label: false %>
                <span><%= localize_day_name(4).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :friday, label: false %>
                <span><%= localize_day_name(5).first(2) %></span>
              </label>
              <label class="checkbox-helper">
                <%= ff.check_box :saturday, label: false %>
                <span><%= localize_day_name(6).first(2) %></span>
              </label>
            <% end %>
          </div>
        <% end %>

        <h5><%= t(:email_settings) %></h5>

        <%= f.check_box :prefer_plain_text, tabindex: tabindex %>
        <%= f.check_box :include_quote_in_reply, tabindex: tabindex %>

        <% if @user.agent? %>

          <%= f.check_box :notify,
              label: t(:receive_new_ticket_notifications), tabindex: tabindex %>

          <h5><%= t(:signature) %></h5>
          <%= f.trix_editor :signature, class: 'mbl', tabindex: tabindex %>
        <% end %>

        <% if can? :create, Labeling.new(labelable: @user) %>
          <h5><%= t(:access_control) %></h5>

          <p><%= t(:have_access_to_label) %></p>

          <%= f.collection_select :label_ids, @labels, :id, :name, {}, {
              multiple: true, class: 'select2 mbl', tabindex: tabindex } %>
        <% end %>

        <% unless Rails.application.secrets[:google_client_id].blank? %>

          <h5><%= t(:omniauth_connect_title) %></h5>

          <p><%= t(:omniauth_connect_text) %></p>

          <%= link_to user_google_oauth2_omniauth_authorize_path do %>
            <i class="fa fa-google-plus-square"></i>
            <%= t(:omniauth_connect_google_text) %>
          <% end %>

        <% end %>

      </div>
    </div>
    <div class="row">
      <div class="medium-12 columns bt">
        <%= f.submit t(:save), class: 'success button radius mtl' %>
      </div>
    </div>

<% end %>
